package com.b00t.server;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.classic.Session;

import com.b00t.client.ItemService;
import com.b00t.server.persistence.HibernateUtil;
import com.b00t.shared.Item;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

public class ItemServiceImpl extends RemoteServiceServlet implements ItemService {

	@Override
	public List<Item> getItemList() {
		List<Item> list = new ArrayList<Item>();
//		list.add(new Item("book", "100"));
//		list.add(new Item("beer", "200"));
//		list.add(new Item("computer", "300"));
		
		//TODO Get the hibernet session and get the items
		
		Session currentSession = HibernateUtil.getSessionFactory().getCurrentSession();
		currentSession.beginTransaction();
		list = new ArrayList<Item>(currentSession.createQuery("from Item").list());
		currentSession.getTransaction().commit();
		return list;
	}

	@Override
	public void deleteItem(String id) {
		System.out.println("Delete Item");

	}

	@Override
	public void addItem(Item item) {
		System.out.println("Add this");
		
	}
}
